﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TuoiThoProject.DAL;

namespace TuoiThoProject.BLL
{
    public class FeedbackBLL
    {
        FeedbackDataContext data = new FeedbackDataContext();

        public List<tblFeedback> getFeedback_All()
        {
            return (from f in data.tblFeedbacks
                    orderby f.nCreatedDate descending
                    select f).ToList();
        }

        public List<tblFeedback> getFeedback_isRead(bool isRead)
        {
            return (from f in data.tblFeedbacks
                    orderby f.nCreatedDate descending
                    where f.isRead == isRead
                    select f).ToList();
        }

        public List<tblFeedback> getFeedback_fromEmail(string Email)
        {
            return (from f in data.tblFeedbacks
                    orderby f.nCreatedDate descending
                    where f.cEmail == Email
                    select f).ToList();
        }

        public void SendFeedback(string Email, string Subject, string Content)
        {
            tblFeedback f = new tblFeedback();
            f.cEmail = Email;
            f.cSubject = Subject;
            f.cContent = Content;
            f.isRead = false;
            f.nCreatedDate = DateTime.Now;

            data.tblFeedbacks.InsertOnSubmit(f);
            data.SubmitChanges();
        }

        public void DeleteFeedback(int FeedbackId)
        {
            tblFeedback f = data.tblFeedbacks.SingleOrDefault(c => c.nFeedbackId == FeedbackId);
            data.tblFeedbacks.DeleteOnSubmit(f);
            data.SubmitChanges();
        }
    }
}